package com.mes_for_xxxxxx.controller;


import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mes_for_xxxxxx.entity.Employee;
import com.mes_for_xxxxxx.entity.common.PageInfo;
import com.mes_for_xxxxxx.entity.common.Result;
import com.mes_for_xxxxxx.entity.dto.LoginDTO;
import com.mes_for_xxxxxx.service.IEmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * <p>
 * 员工信息表 前端控制器
 * </p>
 *
 * @author 179005
 * @since 2024-09-10
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;

    @PostMapping("/page")
    public Result pageEmployee(@RequestBody PageInfo pageInfo){
        int pageSize = pageInfo.getPageSize();
        int pageNum = pageInfo.getPageNum();
        Page<Employee> page = new Page<>(pageNum,pageSize);
        return Result.success(employeeService.page(page));
    }

    /**
     * 扫码登录
     * @param id
     * @return
     */
    @GetMapping("/login/{id}")
    public Result login(@PathVariable Integer id){
        return Result.success(employeeService.login(id));
    }


    @PostMapping("/add")
    public Result addEmployee(@RequestBody Employee employee){
        //name department position skillArea
        employee.setCreatedAt(LocalDateTime.now());
        String string = UUID.randomUUID().toString();
        employee.setWorkYears(0);
        employee.setWorkCode(string);
        employeeService.save(employee);
        return Result.success();
    }
}
